<?php
    include ("includes/config.php");    
    include ("includes/connection.php");
    include ("includes/database.php");
    
    $title = "Register";
    
    include ("header.php");
    
    if (isset($_POST["email"])) {
        $sql = "INSERT INTO authors VALUES(" .
                    "NULL, " .
                    "'" . $_POST["name"] . "', " .
                    "'" . $_POST["email"] . "', " .
                    "'" . md5($_POST["password"]) . "', " .
                    "2" .
               ")";
        
        if (mysql_query($sql)) {
?>
            <h1>You have been registered successfully!</h1>
            <h2>You can login from the following address:</h2>
            <p><a href="<?php echo $CONFIG["base_url"] ?>admin"><?php echo $CONFIG["base_url"] ?>admin</a></p>
<?php
        }
        else {
?>
            <h1>Error!</h1>
            <h2><?php echo mysql_error() ?></h2>
<?php
        }
    }
    else {
?>
    <h1>Register</h1>
    
    <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST">
        <label>Name</label>
        <input type="text" name="name"/>
        
        <label>E-mail</label>
        <input type="text" name="email"/>
        
        <label>Password</label>
        <input type="password" name="password"/>
        
        <br/>
        <input type="submit" value="Register" class="btn btn-warning"/>
    </form>
<?php
    }
    include ("footer.php")
?>